package net.guruqu.cds;

import java.util.Collection;
import java.util.HashMap;
import java.util.Vector;

public class Network {
	private HashMap<Integer, Node> nodes;
	

	private Vector<Integer[]> edge;

	public Integer last_UID = 0;
	public Integer globalCounting;
	
	public boolean globalConverge;
	public boolean globalColourFinished;
	public int maxDeg;

	public Network() {
		nodes = new HashMap<Integer, Node>();
		edge = new Vector<Integer[]>();
	}

	public Node getNode(Integer id) {
		// for(Node n : nodes){
		// if(n.getUID()==id)
		// return n;
		// }
		// return null;
		return nodes.get(id);
	}
	public void setGraph(int numberOfNodes, Vector<int[]> edges) {
		nodes.clear();
		edge.clear();
		last_UID = 0;
		for (int i = 0; i < numberOfNodes; i++) {
			addNode();
		}
		for (int i = 0; i < edges.size(); i++) {
			addEdge(edges.get(i)[0], edges.get(i)[1]);
		}
	}

	public void setGraph(int numberOfNodes, Integer[][] edges) {
		nodes.clear();
		edge.clear();
		last_UID = 0;
		for (int i = 0; i < numberOfNodes; i++) {
			addNode();
		}
		for (int i = 0; i < edges.length; i++) {
			addEdge(edges[i][0], edges[i][1]);
		}
	}

	public Integer addNode() {
		Node node = new ColorNode();
		node.setUID(last_UID++);
		node.setNetwork(this);
		nodes.put(node.getUID(), node);
		return node.getUID();
	}

	public void addEdge(Integer a, Integer b) {
		edge.add(new Integer[] { a, b });
		Node na = getNode(a);
		Node nb = getNode(b);

		na.getNeighbour().add(b);
		nb.getNeighbour().add(a);
	}

	public Collection<Node> getNodes() {
		return nodes.values();
	}

	public Vector<Integer[]> getEdge() {
		return edge;
	}
}
